// app.js
const util = require('./utils/util.js');
const api = require('./utils/api.js');
App({
  onLaunch() {
    let openid = wx.getStorageSync('openid')
    if (!openid){
      let that = this
      wx.login({
        success: res => {
          util.request(api.ApiGetOpenid,{"code":res["code"]}).then(function (res) {
            that.globalData.userInfo = res.data
            wx.setStorageSync('openid', res.data)
          })
        }
      })
    }
    let userInfo = wx.getStorageSync('userInfo')
    if(openid && userInfo){
      let userInfos = JSON.parse(userInfo)
      let params = {
        "avatarUrl":userInfos.avatarUrl,
        "gender":userInfos.gender,
        "nickName":userInfos.nickName,
        "openid":openid,
      }
      util.request(api.ApiUpdateInfo,params).then(function (res) {
      })
    }
  },
  globalData: {
    userInfo: "",
    regneratorRuntime:require("./utils/regenerator-runtime/runtime")
  }
})
